<%--
$Id: category-list.jsp 13 2010-11-02 15:35:59Z feigme $
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/content/commons/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><fmt:message key="category.manager"/></title>
</head>
<body>
<label id="error"><form:errors path="articleCategory.*" cssStyle="color:red;"/></label>
<div>
<%@ include file="article-menu.jsp" %>
<table width="100%" border="0">
	<tr>
		<td colspan="4">
			<form action="${ctx }/admin/category/new" method="post">
			<fmt:message key="category.new"/><input type="text" name="name"/>&nbsp;<input type="submit" name="submit" value="<fmt:message key="common.submit"/>"/><label></label>
			</form>
		</td>
	</tr>
</table>
<table width="50%" class="solidtable">
	<tr>
		<td class="solidtr" width="30" align="center"><fmt:message key="common.id"/></td>
		<td class="solidtr"><fmt:message key="category.name"/></td>
		<td class="solidtr" align="center" width="50"><fmt:message key="category.article.count"/></td>
		<td class="solidtr" align="center" width="50">Sort</td>
		<td class="solidtr" align="center" width="130"><fmt:message key="common.action"/></td>
	</tr>
	<c:forEach items="${categorys}" var="category" varStatus="status">
	<tr style="height:23px;">
		<td align="center"><c:out value="${category.id}"/></td>
		<td>
			<c:out value="${category.name}"/>
		</td>
		<td align="center"><c:out value="${counts[category.id]}"/></td>
		<td align="center">
			<c:if test="${status.index != 0 }">
				<a href="${ctx }/admin/category/<c:out value="${category.id}"/>/up">up</a>
			</c:if>
			<c:if test="${status.index != (fn:length(categorys)-1) }">
				<a href="${ctx }/admin/category/<c:out value="${category.id}"/>/down">down</a>
			</c:if>
		</td>
		<td align="center">
			<a name="update" href="javascript:void(0);"><fmt:message key="common.update"/></a> 
			| <a href="${ctx }/admin/category/<c:out value="${category.id}"/>/delete"><fmt:message key="common.delete"/></a>
		</td>
	</tr>
	<tr style="display: none;height:23px;">
		<td align="center"><c:out value="${category.id}"/></td>
		<td colspan="3">
			<form action="${ctx }/admin/category/<c:out value="${category.id}"/>" method="post">
				<input type="text" name="name" value="<c:out value="${category.name}"/>"/>
				<input type="submit" name="submit" value="<fmt:message key="common.submit"/>"/>
			</form>
		</td>
		<td align="center"><a name="cancel" href="javascript:void(0);"><fmt:message key="common.cancel"/></a></td>
	</tr>
	</c:forEach>
</table>
</div>
<script type="text/javascript">
$(document).ready(function(){
	$("a[name='update']").click(function(){
		$("a[name='cancel']").parent().parent().hide();
		$("a[name='update']").parent().parent().show();
		$(this).parent().parent().hide();
		$(this).parent().parent().next().show();
	});
	$("a[name='cancel']").click(function(){
		$("label").html("");
		$(this).parent().parent().hide();
		$(this).parent().parent().prev().show();
	});
	$("input[name='submit']").click(function(){
		if(jQuery.trim($(this).prev().val())==""){
			$("#error").html("<font color='red'> name is requied.</font>");
			return false;
		}
	});
});
</script>   
</body>
</html>